
CREATE TABLE daycare.Children
  (
   ChildId INT NOT NULL
               IDENTITY(1,1)
               PRIMARY KEY
 , FamilyId INT NOT NULL
 , FirstName VARCHAR(100) NOT NULL
 , LastName VARCHAR(100) NOT NULL
 , NickName VARCHAR(100)
 , DateOfBirth DATE NOT NULL
 , Age AS DATEDIFF(year,DateOfBirth,GETDATE()) - CASE WHEN DATEPART(month,DateOfBirth) > DATEPART(month,GETDATE()) THEN 1
                                                      WHEN DATEPART(month,DateOfBirth) = DATEPART(month,GETDATE())
                                                           AND DATEPART(day,DateOfBirth) > DATEPART(day,GETDATE()) THEN 1
                                                      ELSE 0
                                                 END
 , IsActive BIT NOT NULL
 , ImageId INT NOT NULL
  )
ALTER TABLE daycare.Children ADD CONSTRAINT FK_Children_Images FOREIGN KEY(ImageId) REFERENCES daycare.Images(ImageId)
ALTER TABLE daycare.Children ADD CONSTRAINT FK_Children_Families FOREIGN KEY(FamilyId) REFERENCES daycare.Families(FamilyId)
GO